PATHMac OS 8 and 9 Developer Documentation > Human Interface Toolbox > Control Manager >

Programming With the Mac OS 8.5 Control Manager


Creating a Proportional Scroll Box

Your application should call the function SetControlViewSize to support proportional scroll boxes. If the user selects the systemwide Appearance preference for "Smart Scrolling" and your application doesn't call SetControlViewSize , your application displays the traditional square scroll boxes.

To support a proportional scroll box, simply pass the size of the view area--in terms of whatever units the scroll bar uses--to SetControlViewSize . The system automatically handles resizing the scroll box, once your application supplies this information. Listing 1-1 shows some typical code for setting a scroll bar according to a TextEdit handle, which includes making the scroll box proportional.

Listing 1-1 Adjusting a scroll bar to the viewable text

static pascal void AdjustScrollBarToText
    (TEHandle teh, ControlHandle scrollBar)
{
    // get the values needed to reflect the state of the TEHandle
    short nLines    = (**teh).nLines; // number of lines in doc.
    long totalHeight= TEGetHeight (nLines, 1, teh); // total doc. height
    Rect viewRect   = (**teh).viewRect; // visible area of doc.
    Rect destRect   = (**teh).destRect; // total area of doc.
    short viewHeight= viewRect.bottom - viewRect.top; // vis. doc. height

    // set the min, max, and current value of the scroll bar
    SetControl32BitMinimum (scrollBar, 1);
    SetControl32BitMaximum (scrollBar, totalHeight - viewHeight);
    SetControl32BitValue (scrollBar, viewRect.top - destRect.top);

    // set the scroll bar view size to create a proportional scroll box
    SetControlViewSize (scrollBar, viewHeight);
}

© 1999 Apple Computer, Inc. — (Last Updated 20 Jan 99)